﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using QLHD.Models;
using System.Globalization;
namespace QLHD.Account
{
    public partial class GroupUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            if (Request.Params["GroupID"] != null)
            {
                QLHD2013Entities db = new QLHD2013Entities();

                List<UserUI> lst = new List<UserUI>();

                int groupID = int.Parse(Request.Params["GroupID"].ToString());
                Session["GroupID"] = groupID;
                List<User> lstuser;
                lstuser = db.Users.ToList();
                int i = 1;

                rptUser.DataSource = lstuser;
                rptUser.DataBind();
                //foreach (User item in lstuser)
                //{ 

                //}
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string[] arrListUserID = null;
            if (!string.IsNullOrEmpty(Request.Form["ID"]))
            {
                arrListUserID = Request.Form["ID"].Split(';');
                string groupID = Request.QueryString["GroupID"].ToString();
                if (arrListUserID.Length > 0)
                {
                    for (int i = 0; i < arrListUserID.Length; i++)
                    {
                        QLHD2013Entities db = new QLHD2013Entities();
                        string userID = arrListUserID[i].ToString();
                        if (Request.Form["cbUser_" + userID] != null)
                        {
                            string query = "INSERT INTO groupuser(GroupID,UserID) VALUES (" + groupID + "," + userID + ")";
                            query = string.Format(query);
                            db.ExecuteStoreCommand(query);
                            //lst = db.ExecuteStoreQuery<Group>(query, startRowNumber, endRowNumber).ToList<Group>();
                        }
                        else
                        {
                        }
                    }
                }
                //Response.Redirect("GroupPermissionsUser.Set.aspx?groupID=" + Request.QueryString["groupID"].ToString());
            }
        }
    }
}